﻿{include file="../public/static/html/header.html"}
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="roleName" name="r_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="对角色权限的描述" id="Descripe" name="descripe">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">网站角色：</label>
			<div class="formControls col-xs-8 col-sm-9">
				{volist name="list" id='vo1'}
				<dl class="permission-list">
					<dt>
						<label>
							<input type="checkbox" value="{$vo1[0]['pid']}" name="first-menu" id="user-Character-0">
							{$vo1[0]['pid_name']}</label>
					</dt>
					<dd>
						{volist name="$vo1" id='vo' key='k'}
						<dl class="cl permission-list2">
							<dt>
								<label class="">
									<input type="checkbox" value="{$vo.m_id}" name="two-menu" id="user-Character-0-0">
									{$vo.m_name}</label>
							</dt>
						</dl>
				        {/volist}
					</dd>
				</dl>
				{/volist}
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>
{include file="../public/static/html/last.html"}
<script type="text/javascript">
$(function(){
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	
	$("#form-admin-role-add").validate({
		rules:{
			roleName:{
				required:true,
			},
			Descripe:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var data=$('#form-admin-role-add').serializeArray();
			var postdata=JSON.stringify(data);
			var url ="/admin/role/role_add";
			$.post(url,{data:postdata},function(result)
			{
				if(result.code==1)
				{
					dialog.ok(result.msg);
				}
				else
				{
					dialog.error(result.msg);
				}

			},"JSON");
		}
	});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>